Issue with list DBE

I have built a basic DB with a list and a radioBox with 2 options. I want to populate the list based on which selection has been made. The list is populating just fine, but I having issues with the "delete" function..it seems to only delete 1 or 2 of the current population before repopulating the list. any ideas?

DB box = create("box", styleStandard|styleCentered)
 
string choices[] = {}
string selChoices[] = {"choice one", "choice two"}
DBE choiceList =list(box, "", 10, 10, choices) 
DBE radioSel = radioBox(box, "options", selChoices, 0)
 
int listVol = 0
 
void listOptions1(){
    Module m = read("modname", false)
        AttrType at = find(m, "enum")
        
        int j
        for (j = 0; j < listVol; j++){
                delete(choiceList, j)
        }
        
        listVol = 0     
        int i
        for (i = 0; i < listVol; i++){
                insert(choiceList, i, at.strings[i])
                listVol++
        }
        close(m, false)
}
 
void listOptions2(){
        Module m = read("modulename", false) 
        Object obj
                
        int i
        for (i = 0; i < listVol; i++){
                delete(choiceList, i)
        }
        
        listVol = 0
        int j = 0
        for obj in m do {
                if (obj."Object Text""" != ""){
                        insert(choiceList, j, obj."Object Text""")
                        j++
                        listVol++
                }
        }
        close(m, false)
}
 
void getChoice(DBE placeHolder){
        int x = get(radioSel)
        if (x == 0){
                listOptions1()
        } else if (x == 1){
                listOptions2()
        }
}
set(radioSel, getChoice)
 
realize(box)
listOptions1()
show(box)

SystemAdmin - Thu Jun 30 12:23:37 EDT 2011

Re: Issue with list DBE
llandale - Thu Jun 30 13:12:19 EDT 2011

Stopped studying the code when I found this, so maybe there's another issue.

You need two global 'int' variables to house the length of your lists, perhaps listVol1 and listVol2.

  • Louie

Re: Issue with list DBE
Mathias Mamsch - Thu Jun 30 13:24:38 EDT 2011

If you are going to delete elements from a list you need to go bottom to top, or always delete element 0. After you delete the first element, the second element becomes element 0, so the delete on element 1 will fail and element 2 will remain. Regards, Mathias

By the way: There is an "empty" function that will nicely empty listviews I think ...

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Issue with list DBE
SystemAdmin - Thu Jun 30 13:53:50 EDT 2011

Mathias Mamsch - Thu Jun 30 13:24:38 EDT 2011
If you are going to delete elements from a list you need to go bottom to top, or always delete element 0. After you delete the first element, the second element becomes element 0, so the delete on element 1 will fail and element 2 will remain. Regards, Mathias

By the way: There is an "empty" function that will nicely empty listviews I think ...


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

@Louie: It seems to be working fine with just the one int (after mathias' fix anyway).

@Mathias: That did the trick.

Thanks for the help guys!

-Adam